feat: add iac --exclude param [IAC-3473] #6425
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Submission Checklist
are release-note ready, emphasizing
what was changed, not how.
What does this PR do?
This PR implements the
--excludeparameter for IaC scanning. The implementation is designed to be consistent with the existingsnyk testexclude behavior, focusing on global basename matching.Behavior
--exclude=dir1matches./dir1and./src/dir1/or\) in the exclude flagWhere should the reviewer start?
src/cli/commands/test/iac/local-execution/file-utils.ts- ReviewcreatePathExclusionMatcher. This is where input strings are converted into global glob patterns (**/nameand**/name/**).src/cli/commands/test/iac/local-execution/file-utils.ts- Check howmakeFileAndDirectoryGeneratoruses the matcher to skip excluded branches during the directory walk.How should this be manually tested?
mkdir -p test-iac-exclude/{included,excluded,ignored} printf 'data "aws_iam_policy_document" "s" {\n statement {\n actions = ["*"]\n resources = ["arn:aws:s3:::example"]\n }\n}\n' > test-iac-exclude/included/included.tf cp test-iac-exclude/included/included.tf test-iac-exclude/excluded/excluded.tf cp test-iac-exclude/included/included.tf test-iac-exclude/ignored/ignored.tf # Test single exclusion: only 'included.tf' and 'ignored.tf' should appear snyk iac test --exclude=excluded test-iac-exclude # Test multiple exclusions: only 'included.tf' should appear snyk iac test --exclude=excluded,ignored test-iac-exclude # Test file exclusion: only 'included.tf' and 'excluded.tf' should appear snyk iac test --exclude=ignored.tf test-iac-excludeWhat's the product update that needs to be communicated to CLI users?
New Feature: Exclude files and directories from IaC scans
Users can now exclude specific files and directories from IaC scans using the --exclude parameter:
snyk iac test --exclude=excluded-folder,ignored-file.tfThis update allows you to skip specific files or folders by name, no matter where they are located in your project. If the name matches a folder, Snyk CLI will ignore that folder and every file inside it. This is particularly useful for excluding test files, temporary files, or other non-production IaC files from security scans.
Risk assessment: Low
Any background context you want to provide?
This feature was requested to allow users to exclude test files, temporary files, and other non-production IaC files from security scans.
What are the relevant tickets?